//
//  SHAddPayBankCardController.m
//  JiFengDaRen
//
//  Created by CYF on 2017/3/1.
//  Copyright © 2017年 SH_iOS. All rights reserved.
//
#import "BluetoothCell.h"
#import "SHBankInfoModel.h"
#import "SHUserCenterHttp.h"
#import "SHNerAreaList.h"
#import "TDProvince.h"
#import "SHAddPayBankCardController.h"
#import "ZSYPopoverListView.h"
#import "TDBankSearchViewController.h"
#import "SHCreditCardSearchController.h"
@interface SHAddPayBankCardController ()<UITextFieldDelegate,SHNerAreaListDelegate,ZSYPopoverListDelegate,ZSYPopoverListDatasource,SHCreditCardSearchControllerDelegate>
@property(nonatomic,strong)UILabel *promptLabel;

@property(nonatomic,strong)UIView      *myBgView;
@property(nonatomic,strong)UIView      *firstBgView;
@property(nonatomic,strong)UIView      *secondBgView;
@property(nonatomic,strong)UIView      *thirdBgView;
@property(nonatomic,strong)UIView      *fourthBgView;
@property(nonatomic,strong)UIView      *fiveBgView;
@property(nonatomic,strong)UIView      *sixBgView;

@property(nonatomic,strong)UILabel     *bankCardLabel;
@property(nonatomic,strong)UILabel     *phoneLabel;
@property(nonatomic,strong)UITextField *bankCardTf;
@property(nonatomic,strong)UITextField *phoneTf;
@property(nonatomic,strong)UILabel     *cvvLabel;
@property(nonatomic,strong)UILabel     *expireDateLabel;
@property(nonatomic,strong)UITextField *cvvTf;
@property(nonatomic,strong)UITextField *expireDateTf;
@property(nonatomic,strong)UIButton    *confirmBtn;
@property(nonatomic,strong)NSNumber    *bankCardYype;

@property(nonatomic,strong)UILabel     *bankNameLabel;//银行名称
@property(nonatomic,strong)UILabel     *bankNameButton;

@property(nonatomic,strong)UILabel     *subBankNameLabel;//支行名称
@property(nonatomic,strong)UILabel     *subBankNameButton;


@property(nonatomic,strong)UILabel     *provinceLabel;//省份名称
@property(nonatomic,strong)UILabel     *provinceButton;

@property(nonatomic,strong)UILabel     *cityNameLabel;//城市支行名称
@property(nonatomic,strong)UILabel     *cityNameButton;

@property(nonatomic,strong)NSString     *bankName;
@property(nonatomic,strong)NSString     *subankName;
@property(nonatomic,strong)NSString     *provinceName;
@property(nonatomic,strong)NSString     *cityName;
@property(nonatomic,strong)NSString     *provinceId;
@property(nonatomic,strong)NSString     *cityId;
@property(nonatomic,strong)NSString     *oldpaybankCard;

@property(nonatomic,strong)NSMutableArray *bankNameListArr;
@property(nonatomic,strong)NSArray *cityListArr;









@end

@implementation SHAddPayBankCardController


- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self configUI];
    [self layoutUI];
}
- (NSMutableArray *)bankNameListArr{
    
    if (!_bankNameListArr) {
        
        _bankNameListArr = [NSMutableArray arrayWithCapacity:0];
    }
   
    return _bankNameListArr;
}
#pragma mark -- UI布局
- (void)configUI{
    self.view.backgroundColor = KBASEBGCOLOR;
    if (self.payCardUsingType) {
        
        self.title = @"修改付款银行卡";

    }else{
        self.title = @"添加付款银行卡";

    }
    
    self.myBgView = [[UIView alloc]init];
    self.myBgView.backgroundColor = KBASEBGCOLOR;
    [self.view addSubview:self.myBgView];
    [self.myBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).with.offset(__I6Height(0));
        make.left.equalTo(self.view.mas_left).with.offset(__I6Width(0));
        make.right.equalTo(self.view.mas_right).with.offset(__I6Width(0));
        make.height.mas_equalTo(__I6Height(30));
        
    }];
    self.bankCardYype = @(12);
    self.promptLabel = [[UILabel alloc]init];
    self.promptLabel.text = @"*请绑定持卡人本人的信用卡";
    //@"“银联在线”只适用于会员请注册会员后使用";
//    @"*目前只支持本人信用卡";
    self.promptLabel.textColor = KSHTEXTCOLOR;
    self.promptLabel.font = KSystemFont(__I6Width(13));
    self.promptLabel.textAlignment = NSTextAlignmentLeft;
    [self.myBgView addSubview:self.promptLabel];
    [self.promptLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.myBgView.mas_left).with.offset(__I6Width(15));
            make.centerY.mas_equalTo(self.myBgView.mas_centerY);
            make.right.equalTo(self.myBgView.mas_right).with.offset(__I6Width(-15));
            make.height.mas_equalTo(__I6Height(30));
        }];
//    self.creditBtn = [[MiDaiBaoButton alloc]init];
//    self.creditBtn.tag = 101;
//    self.creditBtn.selected = YES;
//    [self.creditBtn setImage:[UIImage imageNamed:@"midaibao_normal"] forState:UIControlStateNormal];
//    [self.creditBtn setImage:[UIImage imageNamed:@"midaibao_selected"] forState:UIControlStateSelected];
//    [self.creditBtn setTitle:@"信用卡" forState:UIControlStateNormal];
//    [self.creditBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    self.creditBtn.titleLabel.font = KSystemFont(__I6Width(14));
//    [self.myBgView addSubview:self.creditBtn];
//    [self.creditBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.view.mas_left).with.offset(0);
//        make.centerY.mas_equalTo(self.myBgView.mas_centerY);
//        make.width.mas_equalTo(KScreenWidth/2);
//        make.height.mas_equalTo(__I6Height(30));
//    }];
    
//    self.debitBtn = [[MiDaiBaoButton alloc]init];
//    self.debitBtn.tag = 102;
//    [self.debitBtn setTitle:@"借记卡" forState:UIControlStateNormal];
//
//    [self.debitBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    self.debitBtn.titleLabel.font = KSystemFont(__I6Width(14));
//    [self.debitBtn setImage:[UIImage imageNamed:@"midaibao_normal"] forState:UIControlStateNormal];
//    [self.debitBtn setImage:[UIImage imageNamed:@"midaibao_selected"] forState:UIControlStateSelected];
//    [self.myBgView addSubview:self.debitBtn];
//    [self.debitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(self.view.mas_right).with.offset(0);
//        make.centerY.mas_equalTo(self.myBgView.mas_centerY);
//        make.width.mas_equalTo(KScreenWidth/2);
//        make.height.mas_equalTo(__I6Height(30));
//    }];
//
//    [self.debitBtn addTarget:self action:@selector(switchCard:) forControlEvents:UIControlEventTouchUpInside];
//    [self.creditBtn addTarget:self action:@selector(switchCard:) forControlEvents:UIControlEventTouchUpInside];
    
    
    //=====分割线======//
    self.firstBgView = [[UIView alloc]init];
    self.firstBgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.firstBgView];
    
    self.secondBgView = [[UIView alloc]init];
    self.secondBgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.secondBgView];
    
    self.thirdBgView = [[UIView alloc]init];
    self.thirdBgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.thirdBgView];
    
    self.fourthBgView = [[UIView alloc]init];
    self.fourthBgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.fourthBgView];
    
    self.fiveBgView = [[UIView alloc]init];
    self.fiveBgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.fiveBgView];

    self.sixBgView = [[UIView alloc]init];
    self.sixBgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.sixBgView];
    

    
//    self.firstBgView.layer.borderWidth = 0.5;
//    self.firstBgView.layer.borderColor = KLINECOLOR.CGColor;
//    self.secondBgView.layer.borderWidth = 0.5;
//    self.secondBgView.layer.borderColor = KLINECOLOR.CGColor;
//    self.thirdBgView.layer.borderWidth = 0.5;
//    self.thirdBgView.layer.borderColor = KLINECOLOR.CGColor;
//    self.fourthBgView.layer.borderWidth = 0.5;
//    self.fourthBgView.layer.borderColor = KLINECOLOR.CGColor;
//    self.fiveBgView.layer.borderWidth = 0.5;
//    self.fiveBgView.layer.borderColor = KLINECOLOR.CGColor;

//

    

    
    
    self.bankCardLabel = [[UILabel alloc]init];
    self.bankCardLabel.text = @"银行卡号";
    self.bankCardLabel.textColor = [UIColor colorWithHexString:@"#474958"];
    self.bankCardLabel.font = KSystemFont(__I6Width(13));
    [self.firstBgView addSubview:self.bankCardLabel];
    
    self.phoneLabel = [[UILabel alloc]init];
    self.phoneLabel.text = @"手机号";
    self.phoneLabel.textColor = [UIColor colorWithHexString:@"#474958"];
    self.phoneLabel.font = KSystemFont(__I6Width(13));
    [self.secondBgView addSubview:self.phoneLabel];
    
    
    self.bankNameLabel = [[UILabel alloc]init];
    self.bankNameLabel.text = @"银行名称";
    self.bankNameLabel.textColor = [UIColor colorWithHexString:@"#474958"];
    self.bankNameLabel.font = KSystemFont(__I6Width(13));
    [self.fiveBgView addSubview:self.bankNameLabel];
    
    
    self.subBankNameLabel = [[UILabel alloc]init];
    self.subBankNameLabel.text = @"支行名称";
    self.subBankNameLabel.textColor = [UIColor colorWithHexString:@"#474958"];
    self.subBankNameLabel.font = KSystemFont(__I6Width(13));
    [self.sixBgView addSubview:self.subBankNameLabel];
    
    
    
    
    self.provinceLabel = [[UILabel alloc]init];
    self.provinceLabel.text = @"银行卡所属省份";
    self.provinceLabel.textColor = [UIColor colorWithHexString:@"#474958"];
    self.provinceLabel.font = KSystemFont(__I6Width(13));
    [self.thirdBgView addSubview:self.provinceLabel];

    self.cityNameLabel = [[UILabel alloc]init];
    self.cityNameLabel.text = @"银行卡所属城市";
    self.cityNameLabel.textColor = [UIColor colorWithHexString:@"#474958"];
    self.cityNameLabel.font = KSystemFont(__I6Width(13));
    [self.fourthBgView addSubview:self.cityNameLabel];

//    self.phoneLabel = [[UILabel alloc]init];
//    self.phoneLabel.text = @"手机号";
//    self.phoneLabel.textColor = [UIColor colorWithHexString:@"#474958"];
//    self.phoneLabel.font = KSystemFont(__I6Width(13));
//    [self.secondBgView addSubview:self.phoneLabel];
//


    
    //文本框
    self.bankCardTf = [[UITextField alloc]init];
    self.bankCardTf.placeholder = @"请输入银行卡号";
    self.bankCardTf.keyboardType = UIKeyboardTypeNumberPad;
    self.bankCardTf.delegate = self;
    [self.bankCardTf  setValue:[UIColor colorWithHexString:@"#c0c0c7"] forKeyPath:@"_placeholderLabel.textColor"];
    [self.bankCardTf  setValue:KSystemFont(__I6Width(14)) forKeyPath:@"_placeholderLabel.font"];
    self.bankCardTf.font = KSystemFont(__I6Width(14));
    self.bankCardTf.textColor = [UIColor blackColor];
    self.bankCardTf.clearButtonMode  = UITextFieldViewModeAlways;
    [self.firstBgView addSubview: self.bankCardTf ];
    
    self.phoneTf = [[UITextField alloc]init];
    self.phoneTf.delegate = self;
    self.phoneTf.placeholder = @"请输入预留手机号";
    self.phoneTf.keyboardType = UIKeyboardTypeNumberPad;

    self.phoneTf.font = KSystemFont(__I6Width(14));
    self.phoneTf.textColor = [UIColor blackColor];
    [self.phoneTf  setValue:[UIColor colorWithHexString:@"#c0c0c7"] forKeyPath:@"_placeholderLabel.textColor"];
    [self.phoneTf  setValue:KSystemFont(__I6Width(14)) forKeyPath:@"_placeholderLabel.font"];
    self.phoneTf.clearButtonMode = UITextFieldViewModeAlways;
    [self.secondBgView addSubview:self.phoneTf ];
    
    
    
//    self.cvvLabel = [[UILabel alloc]init];
//    self.cvvLabel.text = @"CVV";
//    self.cvvLabel.textColor = [UIColor colorWithHexString:@"#474958"];
//    self.cvvLabel.font = KSystemFont(__I6Width(13));
//    [self.thirdBgView addSubview:self.cvvLabel];
//    
//    self.expireDateLabel = [[UILabel alloc]init];
//    self.expireDateLabel.text = @"有效期";
//    self.expireDateLabel.textColor = [UIColor colorWithHexString:@"#474958"];
//    self.expireDateLabel.font = KSystemFont(__I6Width(13));
//    [self.fourthBgView addSubview:self.expireDateLabel];
    
    
    /*
    //文本框
    self.cvvTf = [[UITextField alloc]init];
    self.cvvTf.placeholder = @"请输入银行卡背面后3位数字";
    self.cvvTf.delegate = self;
    self.cvvTf.keyboardType = UIKeyboardTypeNumberPad;

    [self.cvvTf  setValue:[UIColor colorWithHexString:@"#c0c0c7"] forKeyPath:@"_placeholderLabel.textColor"];
    [self.cvvTf  setValue:KSystemFont(__I6Width(14)) forKeyPath:@"_placeholderLabel.font"];
    self.cvvTf.font = KSystemFont(__I6Width(14));
    self.cvvTf.textColor = [UIColor blackColor];
    self.cvvTf.clearButtonMode  = UITextFieldViewModeAlways;
    [self.thirdBgView addSubview: self.cvvTf ];
    
    self.expireDateTf = [[UITextField alloc]init];
    self.expireDateTf.delegate = self;
    self.expireDateTf.keyboardType = UIKeyboardTypeNumberPad;
    self.expireDateTf.placeholder = @"请输入有效期";
    self.expireDateTf.font = KSystemFont(__I6Width(14));
    self.expireDateTf.textColor = [UIColor blackColor];
    [self.expireDateTf  setValue:[UIColor colorWithHexString:@"#c0c0c7"] forKeyPath:@"_placeholderLabel.textColor"];
    [self.expireDateTf  setValue:KSystemFont(__I6Width(14)) forKeyPath:@"_placeholderLabel.font"];
    self.expireDateTf.clearButtonMode = UITextFieldViewModeAlways;
    [self.fourthBgView addSubview:self.expireDateTf ];
    
*/
    self.bankNameButton = [[UILabel alloc]init];
    self.bankNameButton.font = KSystemFont(__I6Width(13));
    self.bankNameButton.userInteractionEnabled = YES;
    self.bankNameButton.textColor = [UIColor colorWithHexString:@"#474958"];
    self.bankNameButton.text = @"请选择";
    self.bankNameButton.textAlignment = NSTextAlignmentRight;
    UITapGestureRecognizer *bankTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(bankNameButtonClicked:)];
    [self.fiveBgView addGestureRecognizer:bankTap];

    [self.fiveBgView addSubview:self.bankNameButton];
    
    
    
    
    self.subBankNameButton = [[UILabel alloc]init];
    self.subBankNameButton.font = KSystemFont(__I6Width(13));
    self.subBankNameButton.userInteractionEnabled = YES;
    self.subBankNameButton.textColor = [UIColor colorWithHexString:@"#474958"];
    self.subBankNameButton.text = @"请选择";
    self.subBankNameButton.textAlignment = NSTextAlignmentRight;
    //[self.subBankNameButton addTarget:self action:@selector(subBankNameButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    UITapGestureRecognizer *subBankTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(subBankNameButtonClicked:)];
    [self.sixBgView addGestureRecognizer:subBankTap];
    [self.sixBgView addSubview:self.subBankNameButton];
    
    
    self.provinceButton = [[UILabel alloc]init];
    self.provinceButton.font = KSystemFont(__I6Width(13));
    self.provinceButton.userInteractionEnabled = YES;
    self.provinceButton.textColor = [UIColor colorWithHexString:@"#474958"];
    self.provinceButton.text = @"请选择";
    self.provinceButton.textAlignment = NSTextAlignmentRight;
    //[self.provinceButton addTarget:self action:@selector(provinceButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    UITapGestureRecognizer *provinceTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(provinceButtonClicked:)];
    [self.thirdBgView addGestureRecognizer:provinceTap];

    [self.thirdBgView addSubview:self.provinceButton];
    
    
    self.cityNameButton = [[UILabel alloc]init];
    self.cityNameButton.font = KSystemFont(__I6Width(13));
    self.cityNameButton.userInteractionEnabled = YES;
    self.cityNameButton.textColor = [UIColor colorWithHexString:@"#474958"];
    self.cityNameButton.text = @"请选择";
    self.cityNameButton.textAlignment = NSTextAlignmentRight;
    UITapGestureRecognizer *cityTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(cityNameButtonClicked:)];
    [self.fourthBgView addGestureRecognizer:cityTap];

    [self.fourthBgView addSubview:self.cityNameButton];
    
    
    
    self.confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.confirmBtn setBackgroundImage:[UIImage imageNamed:@"btn_bg"] forState:UIControlStateNormal];
    self.confirmBtn.titleLabel.font = KSystemFont(16);
    [self.confirmBtn setTitleColor:KSHTEXTCOLOR forState:UIControlStateNormal];
    [self.confirmBtn setTitle:@"确定" forState:UIControlStateNormal];
    [self.confirmBtn addTarget:self action:@selector(confirmBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.confirmBtn];
    
    if (self.payCardUsingType == 1) {
        self.bankCardTf.text = self.paybankCardModel.bank_card_code;
        self.phoneTf.text = self.paybankCardModel.phone;
        self.oldpaybankCard = self.paybankCardModel.bank_card_code;
    }else{
        self.oldpaybankCard = @"";

    }
    

    


  
    
}
#pragma mark --- 设置控件位置
-(void)layoutUI{
    //设置约束
    
    
    [self.firstBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.myBgView.mas_bottom).with.offset(1);
        make.left.equalTo(self.view.mas_left).with.offset(__I6Width(0));
        make.right.equalTo(self.view.mas_right).with.offset(__I6Width(0));
        make.height.mas_equalTo(__I6Height(42));
        
        
    }];
    
    [self.secondBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.firstBgView.mas_bottom).with.offset(1);
        
        make.left.equalTo(self.view.mas_left).with.offset(__I6Width(0));
        make.right.equalTo(self.view.mas_right).with.offset(__I6Width(0));
        make.height.mas_equalTo(__I6Height(42));
        
        
    }];
    
    [self.thirdBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.secondBgView.mas_bottom).with.offset(1);
        
        make.left.equalTo(self.view.mas_left).with.offset(__I6Width(0));
        make.right.equalTo(self.view.mas_right).with.offset(__I6Width(0));
        make.height.mas_equalTo(__I6Height(42));
        
        
    }];
    
    [self.fourthBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.thirdBgView.mas_bottom).with.offset(1);
        
        make.left.equalTo(self.view.mas_left).with.offset(__I6Width(0));
        make.right.equalTo(self.view.mas_right).with.offset(__I6Width(0));
        make.height.mas_equalTo(__I6Height(42));
        
        
    }];

    [self.fiveBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.fourthBgView.mas_bottom).with.offset(1);
        
        make.left.equalTo(self.view.mas_left).with.offset(__I6Width(0));
        make.right.equalTo(self.view.mas_right).with.offset(__I6Width(0));
        make.height.mas_equalTo(__I6Height(42));
        
        
    }];
    
    
//    [self.sixBgView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.fiveBgView.mas_bottom).with.offset(1);
//        
//        make.left.equalTo(self.view.mas_left).with.offset(__I6Width(0));
//        make.right.equalTo(self.view.mas_right).with.offset(__I6Width(0));
//        make.height.mas_equalTo(__I6Height(42));
//        
//        
//    }];
    [self.bankCardLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.firstBgView.mas_centerY);
        make.left.equalTo(self.firstBgView.mas_left).with.offset(__I6Width(15));
        make.width.mas_equalTo(__I6Width(55));
        make.height.mas_equalTo(__I6Height(42));
        
        
    }];

   
   
    [self.phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.secondBgView.mas_centerY);
        make.left.equalTo(self.secondBgView.mas_left).with.offset(__I6Width(15));
        make.width.mas_equalTo(__I6Width(55));
        make.height.mas_equalTo(__I6Height(42));
        
        
    }];
    
    [self.bankNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.fiveBgView.mas_centerY);
        make.left.equalTo(self.fiveBgView.mas_left).with.offset(__I6Width(15));
        make.width.mas_equalTo(__I6Width(55));
        make.height.mas_equalTo(__I6Height(42));
        
        
    }];
    
//    [self.subBankNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.equalTo(self.sixBgView.mas_centerY);
//        make.left.equalTo(self.sixBgView.mas_left).with.offset(__I6Width(15));
//        make.width.mas_equalTo(__I6Width(55));
//        make.height.mas_equalTo(__I6Height(42));
//        
//        
//    }];
    [self.provinceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.thirdBgView.mas_centerY);
        make.left.equalTo(self.thirdBgView.mas_left).with.offset(__I6Width(15));
        make.width.mas_equalTo(__I6Width(120));
        make.height.mas_equalTo(__I6Height(42));
        
        
    }];
    [self.cityNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.fourthBgView.mas_centerY);
        make.left.equalTo(self.fourthBgView.mas_left).with.offset(__I6Width(15));
        make.width.mas_equalTo(__I6Width(120));
        make.height.mas_equalTo(__I6Height(42));
        
        
    }];
    


    
    
    
    [self.bankCardTf mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.firstBgView.mas_top).with.offset(__I6Height(0));
        make.left.equalTo(self.bankCardLabel.mas_right).with.offset(__I6Width(20));
        make.right.equalTo(self.firstBgView.mas_right).with.offset(__I6Width(-15));
        make.height.mas_equalTo(__I6Height(42));
        
    }];
    
    
    [self.phoneTf mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.secondBgView.mas_top).with.offset(__I6Height(0));
        make.left.equalTo(self.phoneLabel.mas_right).with.offset(__I6Width(20));
        make.right.equalTo(self.secondBgView.mas_right).with.offset(__I6Width(-15));
        make.height.mas_equalTo(__I6Height(42));
        
    }];
    
    
    
    
    /*
    [self.cvvLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.thirdBgView.mas_centerY);
        make.left.equalTo(self.thirdBgView.mas_left).with.offset(__I6Width(15));
        make.width.mas_equalTo(__I6Width(55));
        make.height.mas_equalTo(__I6Height(42));
        
        
    }];
    
    [self.expireDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.fourthBgView.mas_centerY);
        make.left.equalTo(self.fourthBgView.mas_left).with.offset(__I6Width(15));
        make.width.mas_equalTo(__I6Width(55));
        make.height.mas_equalTo(__I6Height(42));
        
        
    }];
    
    
    
    [self.cvvTf mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.thirdBgView.mas_top).with.offset(__I6Height(0));
        make.left.equalTo(self.cvvLabel.mas_right).with.offset(__I6Width(20));
        make.right.equalTo(self.thirdBgView.mas_right).with.offset(__I6Width(-15));
        make.height.mas_equalTo(__I6Height(42));
        
    }];
    
    
    [self.expireDateTf mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.fourthBgView.mas_top).with.offset(__I6Height(0));
        make.left.equalTo(self.expireDateLabel.mas_right).with.offset(__I6Width(20));
        make.right.equalTo(self.fourthBgView.mas_right).with.offset(__I6Width(-15));
        make.height.mas_equalTo(__I6Height(42));
        
    }];
    */
    
    
    [self.bankNameButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.fiveBgView.mas_top).with.offset(__I6Height(0));
        make.left.equalTo(self.bankNameLabel.mas_right).with.offset(__I6Width(20));
        make.right.equalTo(self.fiveBgView.mas_right).with.offset(__I6Width(-30));
        make.height.mas_equalTo(__I6Height(42));
    }];
    
//    [self.subBankNameButton mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.sixBgView.mas_top).with.offset(__I6Height(0));
//        make.left.equalTo(self.subBankNameLabel.mas_right).with.offset(__I6Width(20));
//        make.right.equalTo(self.sixBgView.mas_right).with.offset(__I6Width(-30));
//        make.height.mas_equalTo(__I6Height(42));
//    }];
    

    
    [self.provinceButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.thirdBgView.mas_top).with.offset(__I6Height(0));
        make.left.equalTo(self.provinceLabel.mas_right).with.offset(__I6Width(20));
        make.right.equalTo(self.thirdBgView.mas_right).with.offset(__I6Width(-30));
        make.height.mas_equalTo(__I6Height(42));
    }];
    [self.cityNameButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.fourthBgView.mas_top).with.offset(__I6Height(0));
        make.left.equalTo(self.cityNameLabel.mas_right).with.offset(__I6Width(20));
        make.right.equalTo(self.fourthBgView.mas_right).with.offset(__I6Width(-30));
        make.height.mas_equalTo(__I6Height(42));
    }];
    
    
    [self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.fiveBgView.mas_bottom).with.offset(__I6Height(50));
        make.centerX.mas_equalTo(self.view);
    }];
    
    
    UIImageView *arrow1 = [[UIImageView alloc]init];
    arrow1.image = [UIImage imageNamed:@"jmarrow"];
    [self.thirdBgView addSubview:arrow1];
    [arrow1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.thirdBgView.mas_centerY);
        make.right.equalTo(self.thirdBgView.mas_right).with.offset(__I6Width(-10));
        make.height.mas_equalTo(__I6Height(14));
        make.width.mas_equalTo(__I6Width(7.5));
    }];

    UIImageView *arrow2 = [[UIImageView alloc]init];
    arrow2.image = [UIImage imageNamed:@"jmarrow"];
    [self.fourthBgView addSubview:arrow2];
    [arrow2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.fourthBgView.mas_centerY);
        make.right.equalTo(self.fourthBgView.mas_right).with.offset(__I6Width(-10));
        make.height.mas_equalTo(__I6Height(14));
        make.width.mas_equalTo(__I6Width(7.5));
    }];

    
    UIImageView *arrow3 = [[UIImageView alloc]init];
    arrow3.image = [UIImage imageNamed:@"jmarrow"];
    [self.fiveBgView addSubview:arrow3];
    [arrow3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.fiveBgView.mas_centerY);
        make.right.equalTo(self.fiveBgView.mas_right).with.offset(__I6Width(-10));
        make.height.mas_equalTo(__I6Height(14));
        make.width.mas_equalTo(__I6Width(7.5));
    }];


}

#pragma mark - 选择银行卡名称
- (void)bankNameButtonClicked:(UIButton *)btn{
    [self.view endEditing:YES];

    if (self.provinceName.length == 0) {
        [self.view makeToast:@"请选择省份" duration:1.5 position:@"center"];
        return;
    }
    
    if (self.cityName.length == 0) {
        [self.view makeToast:@"请选择城市" duration:1.5 position:@"center"];
        return;
    }

    SHCreditCardSearchController *cardSearchVc = [[SHCreditCardSearchController alloc]init];
    cardSearchVc.delegate = self;
    [self.navigationController pushViewController:cardSearchVc animated:YES];
    
    
    
}
- (void)searchResultCardModel:(SHBankInfoModel *)cardModel{
    
    SHLog(@"搜索结果 == %@",cardModel.bankName);
    self.bankNameButton.text = cardModel.bankName;
    self.bankName = cardModel.bankName;
}
#pragma mark - 选择支行名称
- (void)subBankNameButtonClicked:(UIButton *)btn{
    
    [self.view endEditing:YES];

    if (self.bankName.length == 0) {
        [self.view makeToast:@"请选择银行" duration:2.0f position:@"center"];
        return;
    }
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
//    [TDHttpEngine requestGetBankListNameCustId:[TDUser defaultUser].custId custMobile:[TDUser defaultUser].custLogin bankProId:self.provinceId  bankCityId:self.cityId bankName:self.bankName complete:^(BOOL succeed, NSString *msg, NSString *cod, NSArray *bankList) {
//        
//        [MBProgressHUD hideHUDForView:self.view animated:YES];
//        if (succeed) {
//            TDBankSearchViewController * search = [[TDBankSearchViewController alloc]initWithNibName:@"TDBankSearchViewController" bundle:[NSBundle bundleWithPath:SRCBUNDLEPATH]];
//            search.delegate = self;
//            search.dataArray = [NSArray arrayWithArray:bankList];
//            [self.navigationController pushViewController:search animated:YES];
//           // __weak  typeof(self) weakSelf = self;
//            search.PopBlock = ^(NSString *branchName){
//
//                self.subankName = branchName;
//                self.subBankNameButton.text = branchName;
//            
//            };
//        }else{
//            [self.view makeToast:msg duration:2.0f position:@"center"];
//        }
//    }];
//    

    
    
}


#pragma mark -
- (NSInteger)popoverListView:(ZSYPopoverListView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.bankNameListArr.count;
}

- (UITableViewCell *)popoverListView:(ZSYPopoverListView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"identifier";
    BluetoothCell *cell = [tableView dequeueReusablePopoverCellWithIdentifier:identifier];
    if (nil == cell)
    {
        cell = [[BluetoothCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.bluetoothLabel.text = self.bankNameListArr[indexPath.row];
    return cell;
}

- (void)popoverListView:(ZSYPopoverListView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.bankNameListArr.count > 0) {
        self.bankName = self.bankNameListArr[indexPath.row];
        self.bankNameButton.text = self.bankName;
    }
}

#pragma mark - 选择省份名称
- (void)provinceButtonClicked:(UITapGestureRecognizer *)tap{
    if (!self.bankCardTf.text) {
        [self.view makeToast:@"请输入银行卡号" duration:1.5 position:@"center"];
        return;
    }
    
    if (!self.phoneTf.text) {
        [self.view makeToast:@"请输入预留手机号" duration:1.5 position:@"center"];
        return;
    }
    
    
   

    [self.view endEditing:YES];
    SHNerAreaList *areaList = [[SHNerAreaList alloc]init];
    areaList.delegate = self;
    [areaList show];
//    STPickerArea *area = [[STPickerArea alloc]init];
//    area.delegate = self;
//    [area show];
    
    
}


#pragma mark - 选择城市名称
- (void)cityNameButtonClicked:(UIButton *)btn{
    [self.view endEditing:YES];
    if (!self.bankCardTf.text) {
        [self.view makeToast:@"请输入银行卡号" duration:1.5 position:@"center"];
        return;
    }
    
    if (!self.phoneTf.text) {
        [self.view makeToast:@"请输入预留手机号" duration:1.5 position:@"center"];
        return;
    }

    SHNerAreaList *areaList = [[SHNerAreaList alloc]init];
    areaList.delegate = self;
    [areaList show];
    
    
}





#pragma mark - 地址选择代理


- (void)pickerArea:(SHNerAreaList *)pickerArea province:(NSString *)province city:(NSString *)city  provinceId:(NSString *)provinceId cityId:(NSString *)cityId  area:(NSString *)area{
    self.provinceButton.text = province;
    self.cityNameButton.text = city;
    self.provinceName = province;
    self.cityName = city;
    self.provinceId = provinceId;
    self.cityId = cityId;
    

    
    
    
}


#pragma mark --- 绑定支付的银行卡
- (void)confirmBtnClicked:(UIButton *)btn{
    [self.view endEditing:YES];
    
    if (self.bankCardTf.text.length == 0) {
        [self.view makeToast:@"请输入银行卡号" duration:1.5 position:@"center"];
        return;
    }else{
        
        if (![SHHelper checkCardNo:self.bankCardTf.text]) {
            [self.view makeToast:
             @"请输入正确的银行卡号" duration:1.f position:@"center"];
            return;
        }
    }
    
    if (self.phoneTf.text.length == 0) {
        [self.view makeToast:@"请输入预留手机号" duration:1.5 position:@"center"];
        return;
    }
    
    if (!self.provinceName) {
        [self.view makeToast:@"请选择省份" duration:1.5 position:@"center"];
        return;
    }
    
    if (!self.cityName) {
        [self.view makeToast:@"请选择城市" duration:1.5 position:@"center"];
        return;
    }
    
    if (!self.bankName) {
        [self.view makeToast:@"请选银行名称" duration:1.5 position:@"center"];
        return;
    }
    
//    if (self.subankName.length == 0) {
//        [self.view makeToast:@"请选择支行名称" duration:1.5 position:@"center"];
//        return;
//    }
        //validity_date  和 cvv
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    [dict setValue:self.bankCardTf.text forKey:@"bank_card_code"];
    [dict setValue:self.phoneTf.text forKey:@"phone"];
    [dict setValue:self.provinceName forKey:@"province"];
    [dict setValue:self.cityName forKey:@"city"];
    [dict setValue:self.bankName forKey:@"bank_name"];
    [dict setValue:@"12" forKey:@"bank_card_type"];
    [dict setValue:@"2" forKey:@"using_choices"];
    [dict setValue:self.oldpaybankCard forKey:@"old_card_code"];
    [self addPayBankCard:dict];
    
    
    //if ([self.bankCardYype isEqual:@(12)]) {
        /*
        if (self.cvvTf.text.length == 0) {
            [self.view makeToast:@"请输入银行卡背面后3位数字" duration:1.5 position:@"center"];
            return;
        }
        if (self.expireDateTf.text.length == 0) {
            [self.view makeToast:@"请输入有效期" duration:1.5 position:@"center"];
            return;
        }
        */

//          params= @{@"bank_card_code":self.bankCardTf.text,@"phone":self.phoneTf.text,@"using_choices":@(2),@"validity_date":self.expireDateTf.text,@"cvv":self.cvvTf.text,@"bank_card_type":@(12)};
//    params= @{@"bank_card_code":self.bankCardTf.text,@"using_choices":@(2),@"bank_card_type":@(12)};
//
//        
//    }else{
//        params= @{@"bank_card_code":self.bankCardTf.text,@"phone":self.phoneTf.text,@"using_choices":@(2)};
//    }
  
//    NSDictionary *params = @{@"bank_card_code":@"6225768769034404",@"phone":@"18074678289",@"using_choices":@(2),@"validity_date":@"0621",@"cvv":@"096",@"bank_card_type":@(12)};
//    

     
   
    
    
    
    
}

#pragma mark - 添加付款卡
- (void)addPayBankCard:(NSDictionary *)params{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [MyDataService requestAFURL:KNEWBANKINFO httpMethod:@"POST" params:params data:nil complection:^(id result) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        //        NSLog(@"添加银行卡信息%@",result);
        if ([result[@"success"] isEqualToNumber:@(1)]) {
            [self.view makeToast:@"添加成功" duration:1.5 position:@"center"];
            
            [self userAuthFouthFailurePop];
        }else{
            
            [self.view makeToast:result[@"data"] duration:1.5 position:@"center"];
            [self userAuthFouthFailurePop];

        }
        
        
        
    } failure:^(id erro) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];

    }];

}

- (void)userAuthFouthFailurePop{
    dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5/*延迟执行时间*/ * NSEC_PER_SEC));
    
    dispatch_after(delayTime, dispatch_get_main_queue(), ^{
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshPayCardNotification" object:nil];
        [self.navigationController popViewControllerAnimated:YES];
        
        
    });

}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}




@end
